package org.esprit.ocm.client.rpc.ec2;

import java.util.List;

import org.esprit.ocm.dto.ec2.impl.ImageDescriptionDto;
import org.esprit.ocm.dto.ec2.impl.InstanceDescriptionDto;
import org.esprit.ocm.dto.impl.AwsCredentialsDto;
import org.esprit.ocm.dto.impl.ServerDto;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("ImageService.rpc")
public interface ImageService extends RemoteService {

	/**
	 * Lists available EC2 AMIs that you could start an instance of.
	 * 
	 * Note that we have to work with arrays here because this class is going to
	 * be exposed as a Web service through Axis2 which does not support Lists.
	 * 
	 * @param all
	 *            set to true to display all public AMIs, set to false to list
	 *            only your own AMIs.
	 * @return Array of Images or null, if no images were found or credentials
	 *         were wrong.
	 */
	public List<ImageDescriptionDto> listImages(boolean all, ServerDto server, AwsCredentialsDto credentials);

	/**
	 * Starts an instance with the given parameters.
	 * 
	 * @param imageId
	 *            AMI-Id of the instance to start.
	 * @param groups
	 *            List of groups.
	 * @param keyName
	 *            Name of the keypair to use.
	 * @param userData
	 *            User data for this instance (see
	 *            http://docs.amazonwebservices.
	 *            com/AWSEC2/2008-05-05/DeveloperGuide
	 *            /index.html?AESDG-chapter-instancedata.html).
	 * @param instanceType
	 *            EC2 Type of the instance
	 * @param count
	 *            number of instances to launch
	 * @param availabilityZone
	 *            Availability zone for instance.
	 * @param kernelId
	 *            KernelId to use. May be empty.
	 * @param ramdiskId
	 *            RamdiskId to use. May be empty.
	 * @return Instance or null in case of error.
	 */
	public String runInstance(String imageId, List<String> groups, String keyName, byte[] userData, String instanceType, int count,
			String availabilityZone, String kernelId, String ramdiskId, ServerDto server, AwsCredentialsDto credentials);

	/**
	 * Blocking start of an instance with the given parameters. Returns only if
	 * startup of instance (or instances, of count > 1) is complete (state is
	 * "running") or if an error occured.
	 * 
	 * @param imageId
	 *            AMI-Id of the instance to start.
	 * @param groups
	 *            List of groups.
	 * @param keyName
	 *            Name of the keypair to use.
	 * @param instanceType
	 *            EC2 Type of the instance
	 * @param count
	 *            number of instances to start with in ReservationDescription
	 * @return Instance(s) (if count > 1) or null in case of error.
	 */
	// public Instance[] runInstanceBlocking(String imageId, String[] groups,
	// String keyName, byte[] userData, InstanceType instanceType, int count,
	// String availabilityZone, String kernelId, String ramdiskId, ServerDto
	// server, AwsCredentialsDto credentials);

	/**
	 * Get or refresh current information on a running instance identified by
	 * its Id.
	 * 
	 * @param instanceId
	 * @return Instance holding the current properties of the instance or null
	 *         in case of error.
	 */
	// public Instance describeInstance(String instanceId, ServerDto server,
	// AwsCredentialsDto credentials);

	/**
	 * Stop a specific AMI instance.
	 * 
	 * @param instanceId
	 * @return TerminatingInstanceDescription or null in case of error.
	 */
	public void stopInstance(List<String> instanceId, ServerDto server, AwsCredentialsDto credentials);

	/**
	 * Stop a specific AMI instance.
	 * 
	 * @param instanceId
	 * @return TerminatingInstanceDescription or null in case of error.
	 */
	// public InstanceStateChangeDescription stopInstance(String instanceId,
	// ServerDto server, AwsCredentialsDto credentials);

	/**
	 * Stop all existing instances.
	 * 
	 * @return List of TerminatingInstanceDescription or null in case of error
	 *         or if no instances were running.
	 */
	// public void stopAllInstances(ServerDto server, AwsCredentialsDto
	// credentials);

	/**
	 * Reboot a given instance.
	 * 
	 * @param instanceId
	 */
	public void rebootInstance(List<String> instanceId, ServerDto server, AwsCredentialsDto credentials);

	/**
	 * 
	 * List all instances.
	 * 
	 * @return List of AMIInstances (may be empty) or null in case of error.
	 */
	public List<InstanceDescriptionDto> listInstances(ServerDto server, AwsCredentialsDto credentials);
}
